import pandas as pd
import numpy as np
from faker import Faker
import random

# 初始化Faker
fake = Faker('zh_CN')

# --- 创建人员信息表 ---
personnel_data = []
# 生成一组唯一的身份证号用于后续关联
id_cards = [fake.ssn() for _ in range(100)]

for ssn in id_cards:
    gender = random.choice(['男', '女'])
    personnel_data.append({
        'id_card': ssn,
        'name': fake.name(),
        'gender': gender,
        'age': random.randint(18, 65),
        'phone': fake.phone_number(),
        'address': fake.address()
    })
personnel_df = pd.DataFrame(personnel_data)

# --- 创建报警记录表 ---
alarm_data = []
alarm_types = ['盗窃', '诈骗', '抢劫', '纠纷', '求助', '其他']
locations = ['中山路', '人民路', '解放路', '北京西路', '广州路', '珠江路']

for i in range(200):
    reporter_id = random.choice(id_cards) # 确保报警人ID存在于人员表中
    alarm_data.append({
        'alarm_id': 20250001 + i,
        'alarm_time': fake.date_time_between(start_date='-1y', end_date='now'),
        'alarm_type': random.choice(alarm_types),
        'location': random.choice(locations) + str(random.randint(1, 200)) + '号',
        'reporter_id': reporter_id
    })
alarm_df = pd.DataFrame(alarm_data)

# --- 保存为CSV文件 ---
# 创建目录（如果不存在）
import os
output_dir = 'final_product'
os.makedirs(output_dir, exist_ok=True)

personnel_df.to_csv(f'{output_dir}/mock_personnel.csv', index=False, encoding='utf-8-sig')
alarm_df.to_csv(f'{output_dir}/mock_alarm.csv', index=False, encoding='utf-8-sig')

print(f"模拟数据已成功生成到 {output_dir} 目录下：mock_personnel.csv, mock_alarm.csv")
